/**
 * 
 */
package de.wemwolf.client.net;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import de.wemwolf.server.ServerRMIImpl;

/**
 * Client side proxy object to communicate with the server.
 * 
 * @author Sheepy, Andre
 * 
 */
public class ServerConnectorRMI {

	private ServerRMIImpl server;

	/**
	 * 
	 * @param host the host address
	 */
	public ServerConnectorRMI(String host) {

		Registry registry;
		try {
			registry = LocateRegistry.getRegistry(host);
			server = (ServerRMIImpl) registry.lookup("server");
		} catch (RemoteException e) {
			System.err.println("Client exception: " + e.toString());
			e.printStackTrace();
		} catch (NotBoundException e) {
			System.err.println("Client exception: " + e.toString());
			e.printStackTrace();
		}

	}

	/**
	 * RMI test method
	 */
	public void test() {
		try {
			String response = server.foo(1);
			System.out.println("response: " + response);
		} catch (Exception e) {
			System.err.println("Client exception: " + e.toString());
			e.printStackTrace();
		}

	}

}
